package de.kimera.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import de.kimera.api.IEmployee;
import de.kimera.utils.Utils;

public class Employee implements IEmployee{
	private String firstName;
	private String lastName;
	private String serviceName;//unique id
	
	private Date birthDate;
	private String address;
	private String emailAddress;
	
	private List<Shift> shifts;

	public Employee(String firstName, String lastName, String serviceName, Date birthDate, String address,
			String emailAddress) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.serviceName = serviceName;
		this.birthDate = birthDate;
		this.address = address;
		this.emailAddress = emailAddress;
		this.shifts = new LinkedList<Shift>();
	}

	public Employee() {
	}
	
	//GETTERs
	public String getFirstName() {
		return firstName;
	}

	public String getLastName() {
		return lastName;
	}
	
	public String getServiceName() {
		return serviceName;
	}
	
	public String getBirthDateString() {
		return Utils.convertDateToString(birthDate,Utils.BIRTHDATE_FORMAT);
	}
	
	public String getAddress() {
		return address;
	}
	
	public String getEmailAddress() {
		return emailAddress;
	}

	public List<Shift> getShifts() {
		return shifts;
	}
	
	//SETTERs
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public void setBirthDateString(String birthDateText){
		Date result = Utils.convertStringToDate(birthDateText, Utils.BIRTHDATE_FORMAT); 
		
		if(result !=null){
			birthDate = result; 
		}
		
    }

	public void setAddress(String address) {
		this.address = address;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	//OTHERs
	public void addShift(Shift shift){
		shifts.add(shift);
	}
	
	@Override
	public String toString() {
		return "Employee [firstName=" + firstName + ", lastName=" + lastName + ", dienstName=" + serviceName
				+ ", birthDate=" + birthDate + ", address=" + address + ", emailAddress=" + emailAddress + ", shifts="
				+ shifts + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((address == null) ? 0 : address.hashCode());
		result = prime * result + ((birthDate == null) ? 0 : birthDate.hashCode());
		result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode());
		result = prime * result + ((shifts == null) ? 0 : shifts.hashCode());
		result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode());
		result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
		result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Employee other = (Employee) obj;
		if (address == null) {
			if (other.address != null)
				return false;
		} else if (!address.equals(other.address))
			return false;
		if (birthDate == null) {
			if (other.birthDate != null)
				return false;
		} else if (!birthDate.equals(other.birthDate))
			return false;
		if (serviceName == null) {
			if (other.serviceName != null)
				return false;
		} else if (!serviceName.equals(other.serviceName))
			return false;
		if (shifts == null) {
			if (other.shifts != null)
				return false;
		} else if (!shifts.equals(other.shifts))
			return false;
		if (emailAddress == null) {
			if (other.emailAddress != null)
				return false;
		} else if (!emailAddress.equals(other.emailAddress))
			return false;
		if (firstName == null) {
			if (other.firstName != null)
				return false;
		} else if (!firstName.equals(other.firstName))
			return false;
		if (lastName == null) {
			if (other.lastName != null)
				return false;
		} else if (!lastName.equals(other.lastName))
			return false;
		return true;
	}
}
